import{Jt as e,u as t}from"./B2uw_jGT1oIxh7.js";var n={isTrue:`🟢`,isFalse:`🔴`,exists:`✅`,empty:`∅`,eq:`=`,ne:`≠`};function r(e,t,r,i){if(!e)return`Bedingung`;if(t===`isTrue`||t===`isFalse`){let r=i.find(t=>t.id===e)?.title||e;return`${n[t]} ${r}`}return t===`eq`||t===`ne`?`${e} ${n[t]} ${r||`…`}`:`${e} ${n[t]??t}`}var i=t.create({name:`conditional`,group:`inline`,inline:!0,content:`inline*`,selectable:!0,draggable:!1,addOptions(){return{conditions:()=>[]}},addAttributes(){return{field:{default:``},operator:{default:`exists`},value:{default:``}}},parseHTML(){return[{tag:`span[data-conditional]`,getAttrs:e=>({field:e.getAttribute(`data-field`)??``,operator:e.getAttribute(`data-operator`)??`exists`,value:e.getAttribute(`data-value`)??``})}]},renderHTML({HTMLAttributes:t,node:n}){let i=String(n.attrs.field??``),a=String(n.attrs.operator??`exists`),o=String(n.attrs.value??``);return[`span`,e(t,{"data-conditional":``,"data-field":i,"data-operator":a,"data-value":o,"data-label":r(i,a,o,this.options.conditions?.()??[]),class:`oui-richtext-conditional`}),0]},addCommands(){let e=this.type;return{setConditional:t=>({state:n,dispatch:r,tr:i})=>{let{from:a,to:o,empty:s}=n.selection;if(s)return!1;let c=n.doc.resolve(a),l=n.doc.resolve(o);if(!c.sameParent(l)||!c.parent.inlineContent)return!1;let u=n.doc.slice(a,o),d=u.content.firstChild,f=d?.isTextblock?d.content:u.content,p=e.create(t,f);return r&&i.replaceRangeWith(a,o,p).scrollIntoView(),!0},updateConditional:t=>({state:n,dispatch:r,tr:i})=>{let{$from:a}=n.selection;for(let n=a.depth;n>=0;n--){let o=a.node(n);if(o.type===e){let e=a.before(n);return r&&i.setNodeMarkup(e,void 0,{...o.attrs,...t}),!0}}return!1},unsetConditional:()=>({state:t,dispatch:n,tr:r})=>{let{$from:i}=t.selection;for(let t=i.depth;t>=0;t--){let a=i.node(t);if(a.type===e){let e=i.before(t),o=i.after(t);return n&&r.replaceWith(e,o,a.content),!0}}return!1}}}});export{i as Conditional};